﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DotNetCore.BannerManagement.Domain;
using DotNetCore.BannerManagement.Domain;
using Microsoft.Practices.Repository;
using System.Globalization;
using System.Data.SqlClient; 


namespace DotNetCore.BannerManagement.DAL.Domain.dnc_ZoneImageRepositoryArtifacts
{
    /// <summary>
    /// A factory object that is responsible for taking a dnc_ZoneImage
    /// and generating the corresponding SQL to insert that
    /// dnc_ZoneImage into the database. It also includes a method
    /// to grab the returned ID from the call and updating the
    /// dnc_ZoneImage object with it.
    /// </summary>
    internal sealed class dnc_ZoneImageInsertFactory : IDbToBusinessEntityNameMapper, IInsertFactory<dnc_ZoneImage>
    {
        /// <summary>
        /// Creates the dnc_ZoneImageInsertFactory to build an insert statement for
        /// the given dnc_ZoneImage object.
        /// </summary>
        public dnc_ZoneImageInsertFactory()
        {
        }

		#region IInsertFactory<dnc_ZoneImage> Members
		
        public DbCommand ConstructInsertCommand(Database db, dnc_ZoneImage dnc_ZoneImage)
        {            
			DbCommand command = db.GetStoredProcCommand("Insertdnc_ZoneImage");
			
			    db.AddInParameter(command, "id", DbType.Int32, dnc_ZoneImage.Id);
			    db.AddInParameter(command, "imageHeight", DbType.Decimal, dnc_ZoneImage.ImageHeight);
			    db.AddInParameter(command, "imageWidth", DbType.Decimal, dnc_ZoneImage.ImageWidth);
			if(dnc_ZoneImage.Name == null)
            {
                db.AddInParameter(command, "name", DbType.String);
            }
            else
            {
			    db.AddInParameter(command, "name", DbType.String, dnc_ZoneImage.Name);
            }

			return command;
        }

        public void SetNewID(Database db, DbCommand command, dnc_ZoneImage dnc_ZoneImage)
        {
            System.Int32 id1 = (System.Int32)(db.GetParameterValue(command, "id"));
	dnc_ZoneImage.Id = id1;
	
        }
        
        #endregion
        
		#region IDbToBusinessEntityNameMapper Members
        /// <summary>
        /// Maps a field name in the database (usually a parameter name for a stored proc)
        /// to the corresponding business entity property name.
        /// </summary>
        /// <remarks>This method is intended for error message handling, not for reflection.</remarks>
        /// <param name="dbParameter">Name of field/parameter that the database knows about.</param>
        /// <returns>Corresponding business entity field name.</returns>
        public string MapDbParameterToBusinessEntityProperty(string dbParameter)
        {
            switch (dbParameter)
            {
				case "imageHeight":
					return "ImageHeight";
				case "imageWidth":
					return "ImageWidth";
				case "name":
					return "Name";
				default:
					throw new Exception(dbParameter);
			}
        }
        #endregion        
    }

}

